<template>
  <div class="panel">
    <div class="data-overview">
      <div class="overview-column">
        <!-- 设备总数 -->
        <div class="data-card large">
          <div class="card-icon">
            <el-icon><Monitor /></el-icon>
          </div>
          <div class="card-info">
            <div class="card-title">智能设备总数</div>
            <div class="card-value">
              <span class="number">{{ deviceData.total }}</span>
              <span class="unit">个</span>
            </div>
          </div>
        </div>

        <!-- 在线设备 -->
        <div class="data-card">
          <div class="card-icon">
            <el-icon><Connection /></el-icon>
          </div>
          <div class="card-info">
            <div class="card-title">在线设备</div>
            <div class="card-value">
              <span class="number">{{ deviceData.online }}</span>
              <span class="unit">个</span>
            </div>
          </div>
        </div>

        <!-- 告警设备 -->
        <div class="data-card">
          <div class="card-icon warning">
            <el-icon><Warning /></el-icon>
          </div>
          <div class="card-info">
            <div class="card-title">今日告警</div>
            <div class="card-value warning">
              <span class="number">{{ deviceData.alarm }}</span>
              <span class="unit">条</span>
            </div>
          </div>
        </div>
      </div>

      <div class="overview-column">
        <!-- 离线设备 -->
        <div class="data-card">
          <div class="card-icon offline">
            <el-icon><Switch /></el-icon>
          </div>
          <div class="card-info">
            <div class="card-title">监控面积</div>
            <div class="card-value offline">
              <span class="number">878</span>
              <span class="unit">亩</span>
            </div>
          </div>
        </div>

        <!-- 设备类型 -->
        <div class="data-card">
          <div class="card-icon">
            <el-icon><Grid /></el-icon>
          </div>
          <div class="card-info">
            <div class="card-title">基地面积</div>
            <div class="card-value">
              <span class="number">1302</span>
              <span class="unit">亩</span>
            </div>
          </div>
        </div>

        <!-- 运行时长 -->
        <div class="data-card">
          <div class="card-icon">
            <el-icon><Timer /></el-icon>
          </div>
          <div class="card-info">
            <div class="card-title">基地数量</div>
            <div class="card-value">
              <span class="number">2</span>
              <span class="unit">个</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import {
  Monitor,
  Connection,
  Warning,
  Switch,
  ArrowUp,
  ArrowDown,
  Grid,
  Timer
} from '@element-plus/icons-vue'

// 模拟数据
const deviceData = ref({
  total: 37,
  online: 32,
  offline: 8,
  alarm: 3,
  trend: 5.2,
  types: 8,
  runtime: 8760
})

// 定时更新数据

</script>

<style scoped>
.panel {
  height: 100%;
  padding: 1rem;
}

.data-overview {
  display: flex;
  gap: 1rem;
  height: 100%;
}

.overview-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.data-card {
  background: rgba(18, 161, 127, 0.1);
  border-radius: 8px;
  padding: 1.2rem;
  display: flex;
  gap: 1rem;
  backdrop-filter: blur(5px);
  border: 1px solid rgba(51, 255, 208, 0.1);
  flex: 1;
  min-height: 0;
  align-items: center;
}

.data-card.large {
  flex: 1.2;
}

.card-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 4.5rem;
  height: 4.5rem;
  flex-shrink: 0;
}

.card-icon::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.card-icon .el-icon {
  position: relative;
  z-index: 2;
  color: #33ffd0;
  font-size: 2.4rem;
  /* 位置上移 */
  margin-top: -0.5rem;
  animation: float 2s ease-in-out infinite;
}

.card-icon.warning::before {
  filter: hue-rotate(140deg) brightness(1.2);
}

.card-icon.warning .el-icon {
  color: #ff6b6b;
}

.card-icon.offline::before {
  filter: hue-rotate(70deg) brightness(1.2);
}

.card-icon.offline .el-icon {
  color: #ffd166;
}

.card-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
}

.card-title {
  font-size: 1rem;
  color: rgba(51, 255, 208, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-value {
  display: flex;
  align-items: flex-end;
  gap: 0.3rem;
  line-height: 1;
}

.card-value .number {
  font-size: 2.4rem;
  font-weight: bold;
  color: #33ffd0;
  text-shadow: 0 0 10px rgba(51, 255, 208, 0.3);
}

.card-value .unit {
  font-size: 1.2rem;
  color: rgba(51, 255, 208, 0.8);
  margin-bottom: 0.4rem;
}

.card-rate {
  font-size: 0.85rem;
  color: rgba(51, 255, 208, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.2rem;
}

.trend {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  margin-top: 0.3rem;
}

.trend-value {
  color: rgba(51, 255, 208, 0.8);
}

.trend-value.up {
  color: #33ffd0;
}

.trend-value.down {
  color: #ff6b6b;
}

.el-icon.up {
  color: #33ffd0;
}

.el-icon.down {
  color: #ff6b6b;
}

.warning .number,
.warning .unit {
  color: #ff6b6b;
  text-shadow: 0 0 10px rgba(255, 107, 107, 0.3);
}

.offline .number,
.offline .unit {
  color: #ffd166;
  text-shadow: 0 0 10px rgba(255, 209, 102, 0.3);
}

@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}
</style>
